package com.kq.tallybookl.util;

import android.content.Context;
import android.telephony.TelephonyManager;

import java.util.Random;

/**
 * 获取设备标示信息
 *
 * Created by Kq on 2016/4/29.
 */
public class GetIMEI {

    /**
     * 获取手机的IMEI号
     * @param context
     * @return
     */
    public static String getIMEI(Context context){
        TelephonyManager TelephonyMgr =
                (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        String imei = TelephonyMgr.getDeviceId();

        // 如果获取不到IMEI号，则随机生成一个
        if(imei==null){
            Random random = new Random();
            String random_imei = "";
            for(int i = 0;i<15;i++){
                random_imei = random_imei+random.nextInt(9);
            }
            imei = random_imei;
        }

        return GetMD5.getMD5(imei);
    }
}
